
#include <stdio.h>
#include "ISerial.h"

#ifndef _IFILE_H
#define _IFILE_H
//---------------------------------------------------------------------------------------------
#define SAVE(name,serial,result) 	CIFile file;\
	if(file.Open(##name, "wb")){\
	CIArchive ar(&file, CIArchive::W);\
	serial(ar);\
	if(file.Error() != CIFile::ERR_NO)\
	{\
	*result = false;\
	}\
	else\
	{\
	*result = true;\
	}\
	file.Close();\
	}\
	else\
	*result = false;


#define LOAD(name,serial,result)  	CIFile file;\
	if(file.Open(##name, "rb"))\
{  CIArchive ar(&file, CIArchive::R);\
	serial(ar);\
	if(file.Error() != CIFile::ERR_NO)\
	{\
	*result = false;\
	}\
else{\
	*result = true;\
	}\
	file.Close();}\
else\
	*result = false;


//----------------------------------------------------------------------------------------------

class CIFile : public CISerial
{
public:
	CIFile();
	~CIFile();

	bool Open(const char* szFileName, const char *mode);
	bool Close();

	virtual int Read(void* pBuf, int nSize);
	virtual int Write(void* pBuf, int nSize);
	virtual int Error();
	virtual int Size(int flag);

private:
	FILE* m_pFILE;   
	int   m_nErrorCode;

	int   m_nSize;
};

#endif